package com.kuhyygy.activity;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.kuhyygy.R;

public class ContentProviderActivity extends BaseActivity {

	private String tag = "ContentProviderActivity";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.testcprovider);
		Button add = (Button) this.findViewById(R.id.cpAdd);
		Button adds = (Button) this.findViewById(R.id.cpAdds);
		Button update = (Button) this.findViewById(R.id.cpUpdate);
		Button updates = (Button) this.findViewById(R.id.cpUpdates);
		Button del = (Button) this.findViewById(R.id.cpDelete);
		Button dels = (Button) this.findViewById(R.id.cpDeletes);

		add.setOnClickListener(l);
		adds.setOnClickListener(l);
		update.setOnClickListener(l);
		updates.setOnClickListener(l);
		del.setOnClickListener(l);
		dels.setOnClickListener(l);
	}

	private OnClickListener l = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.cpAdd:
				add();
				break;
			case R.id.cpAdds:
				adds();
				break;
			case R.id.cpUpdate:
				update();
				break;
			case R.id.cpUpdates:
				updates();
				break;
			case R.id.cpDelete:
				del();
				break;
			case R.id.cpDeletes:
				dels();
				break;
			default:
				break;
			}
		}
	};

	protected void add() {
		ContentResolver r = this.getContentResolver();
		Uri uri = null;
		ContentValues cv = new ContentValues();
		uri = Uri.parse("content://com.kuhyygy.sqlite.provider.userContentProvider/user/1");
		cv.put("name", "cpAdd");
		Log.i(tag, "add one User：" + r.insert(uri, cv).toString());
	}

	protected void adds() {
		ContentResolver r = this.getContentResolver();
		Uri uri = null;
		ContentValues cv = new ContentValues();
		uri = Uri.parse("content://com.kuhyygy.sqlite.provider.userContentProvider/user");
		cv.put("name", "cpAddUsers");
		Log.i(tag, "add one User: " + r.insert(uri, cv).toString());
	}

	protected void dels() {
		ContentResolver r = this.getContentResolver();
		Uri uri = Uri.parse("content://com.kuhyygy.sqlite.provider.userContentProvider/user");
		Log.i(tag, "dels users: " + r.delete(uri, "id = ?", new String[]{String.valueOf(1)}));
	}

	protected void del() {
		ContentResolver r = this.getContentResolver();
		Uri uri = Uri.parse("content://com.kuhyygy.sqlite.provider.userContentProvider/user/6");
		Log.i(tag, "dels users: " + r.delete(uri, null, null));
	}

	protected void updates() {
		// TODO Auto-generated method stub

	}

	protected void update() {
		// TODO Auto-generated method stub

	}

}
